<template>
  <div>
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>
          <i class="el-icon-lx-calendar"></i>全局配置
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="container">
      <div class="form-box">
        <el-form ref="form" :model="form" label-width="200px">
          <el-form-item label="安卓下载链接">
            <el-input v-model="form.androidDownloadLink"></el-input>
          </el-form-item>
          <el-form-item label="上传apk文件">
            <el-upload class="upload-demo" drag :http-request="uploadFileMethod" action="https://jsonplaceholder.typicode.com/posts/" multiple>
              <i class="el-icon-upload"></i>
              <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
            </el-upload>
          </el-form-item>
          <el-form-item label="安卓版本号">
            <el-input v-model="form.androidVersion"></el-input>
          </el-form-item>
          <el-form-item label="苹果下载链接">
            <el-input v-model="form.iosDownloadLink"></el-input>
          </el-form-item>
          <el-form-item label="苹果版本号">
            <el-input v-model="form.iosVersion"></el-input>
          </el-form-item>
          <el-form-item label="上架审核">
            <el-radio-group v-model="form.isGoOnline">
              <el-radio label="0">无审核</el-radio>
              <el-radio label="1">审核中</el-radio>
            </el-radio-group>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" @click="onSubmit()">表单提交</el-button>
            <el-button>取消</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import { upload, api } from "@/api/index";
export default {
  name: "baseform",
  inject: ["reload"],
  data() {
    return {
      form: {
        initIntegral: '',
        initPrice: '',
        maxShop: '',
        maxShopCount: '',
        outPrice: '',
      },
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      api('/admin/usersAppConfig/select', {
        parentId: this.$store.state.adminMsg.parentId,
      }).then((res) => {
        this.form = res.data;
      });
    },
    //多图上传
    uploadFileMethod(param) {
      let formData = new FormData();
      if (param.file) {
        formData.append("file", param.file);
      } else {
        formData.append("file", param);
      }
      upload(formData).then((res) => {
        this.form.androidDownloadLink = `http://xiuhaoshenghuo.xsiuyang.com/imgs/${res.data[0].fileName}`;
      });
    },
    onSubmit() {
      api('/admin/usersAppConfig/update', this.form).then((res) => {
        if (res.code === 2000) {
          this.$message.success(res.message);
          this.reload();
        } else {
          this.$message.error(res.message);
        }
      });
    },
  },
  created() { },
};
</script>
<style scoped>
.pre-img {
  width: 100px;
  height: 100px;
  background: #f8f8f8;
  border: 1px solid #eee;
  border-radius: 5px;
}

.crop-demo {
  display: flex;
  align-items: flex-end;
}

.crop-input {
  position: absolute;
  width: 102px;
  height: 102px;
  left: 0px;
  top: 0px;
  opacity: 0;
  cursor: pointer;
}
</style>